﻿using AutoFixture;
using DataInit.DataContexts.SpecimenBuilders;
using DataInit.Entities;
using Stee.CAP8.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataInit.DataContexts.DataGenerate
{


    public class DataGenerator
    {
        private PTDBContext pTDBContext;
        public DataGenerator(PTDBContext pTDBContext)
        {
            this.pTDBContext = pTDBContext;
        }

        public Task<IEnumerable<LoginOperator>> GenerateLoginOperators()
        {
            var fix = new Fixture();
            var list = fix.Build<LoginOperator>()
                .Without(a => a.ID)
                .Without(a => a.RequestID)
                .CreateMany(50);
            return Task.FromResult(list);
        }

        public Task<IEnumerable<Incident>> GenerateIncidentEntities()
        {
            var fix = new Fixture();
            fix.Customizations.Add(new StringPropertyTruncateSpecimenBuilder<Incident>(p => p.OperatorId, pTDBContext));
            var list = fix.Build<Incident>()
                .Without(a => a.ID)
                .Without(a => a.RequestID)
                .CreateMany(1000);

            return Task.FromResult(list);
        }


        public Task<IEnumerable<IncidentAddress>> GenerateIncidentAddresses(IEnumerable<Incident> incidents)
        {
            var count = incidents.Count();
            var fix = new Fixture();
            var list = fix.Build<IncidentAddress>()
                .Without(a => a.ID)
                .Without(a => a.RequestID)
                .CreateMany(count);

            var listAction = fix.Build<ActionEntity>()
                .Without(a => a.ID)
                .Without(a => a.RequestID)
                .CreateMany(count);
            for (var i = 0; i < count; i++)
            {
                var incident = incidents.ElementAt(i);
                var address = list.ElementAt(i);
                address.IncidentNumber = incident.IncidentNumber;
                var action = listAction.ElementAt(i);
                action.IncidentNumber = incident.IncidentNumber;
                action.AssignTo = incident.OperatorId;
                


            }




            return Task.FromResult(list);
        }





    }
}
